package com.zxcl.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zxcl.domain.Order;
import com.zxcl.dto.OrderConfirmDTO;
import com.zxcl.dto.OrderSubmitDTO;
import com.zxcl.dto.PageDTO;
import com.zxcl.model.Result;
import com.zxcl.service.OrderService;
import com.zxcl.vo.OrderConfirmVO;
import com.zxcl.vo.OrderStatusVO;
import com.zxcl.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 描述: [订单管理相关API]
 * 作者: zxcl
 */
@RestController
@Api(tags = "订单管理接口")
@RequestMapping("p/myOrder")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 查询订单状态数量
     * @return
     */
    @GetMapping("orderCount")
    @ApiOperation("查询订单状态数量")
    public Result<OrderStatusVO> orderStatusCount() {
        OrderStatusVO orderStatusVO = orderService.orderStatusCount();
        return Result.success(orderStatusVO);
    }

    //order-service/p/myOrder/myOrder?current=1&size=10&status=1
    @GetMapping("myOrder")
    @ApiOperation("分页查询订单列表")
    public Result<Page<OrderVO>> loadOrderPage(PageDTO pageDTO,Integer status){

        Page<OrderVO> orderPage = orderService.loadOrderPage(pageDTO,status);


        return Result.success(orderPage);
    }

    /**
     * 订单确认
     * @param orderConfirmDTO
     * @return
     */
    @PostMapping("confirm")
    @ApiOperation("订单确认")
    public Result<OrderConfirmVO> orderConfirm(@RequestBody OrderConfirmDTO orderConfirmDTO) {
        OrderConfirmVO orderConfirmVO = orderService.orderConfirm(orderConfirmDTO);
        return Result.success(orderConfirmVO);

    }

    /**
     * 下预定单
     */
    @PostMapping("submit")
    @ApiOperation("下预订单")
    public Result<Map<String,String>> orderSubmit(@RequestBody OrderSubmitDTO orderSubmitDTO){
        Map<String,String> result = this.orderService.orderSubmit(orderSubmitDTO);
        return Result.success(result);
    }


}
